package szf.im.client;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import szf.im.client.boot.Client;
import szf.im.client.data.MessageOuterClass;
import szf.im.client.util.Cfg;
import szf.im.client.util.SpringUtil;

import java.util.Scanner;

/**
 * @author shizhanfu
 */
@SpringBootApplication
public class ClientApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        Cfg cfg = SpringUtil.GetBean(Cfg.class);
        while (true){
            Scanner scanner = new Scanner(System.in);
            String ipt = scanner.nextLine();
            System.out.println("you input:" + ipt);
            MessageOuterClass.Message msg = MessageOuterClass.Message.newBuilder()
                    .setUserId(cfg.getuId()).setMsgType(MessageOuterClass.Message.MsgType.sendTxt)
                    .setInfo(ipt).build();
            SpringUtil.GetBean(Client.class).channel.writeAndFlush(msg);

        }
    }
}
